// custom-tab-bar/index.js
import { storeBindingsBehavior } from 'mobx-miniprogram-bindings'
import { store } from '../store/store'

Component({

  behaviors: [storeBindingsBehavior],
  storeBindings: {
    store,
    fields: {
      active: 'activeIndex'
    },
    actions: {
      updateActive: 'updateActiveIndex'
    }

  },
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    active: 0,
    info: 0,
    pageList: [
      {
        pagePath: "/pages/home/home",
        text: "首页",
        icon: "home-o"
      },
      {
        pagePath: "/pages/type/type",
        text: "分类",
        icon: "list-switch"
      },
      {
        pagePath: "/pages/shopcar/shopcar",
        text: "购物车",
        icon: "cart-circle-o"
      },
      {
        pagePath: "/pages/mine/mine",
        text: "我的",
        icon: "manager-o"
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      // event.detail 的值为当前选中项的索引
      this.updateActive(event.detail)
      wx.switchTab({
        url: this.data.pageList[event.detail].pagePath,
      })
    }
  }
})
